package org.zxl.api;

import com.alibaba.fastjson.JSON;
import org.zxl.api.common.PlatformInfoCache;
import org.zxl.api.common.funcInterface.CheckAuthFailExceptionHandler;
import org.zxl.api.common.funcInterface.HttpHeaderBuilder;
import org.zxl.api.common.funcInterface.HttpResponseParse;
import org.zxl.api.platform.dto.AuthInfo;
import org.zxl.api.common.util.HttpClient;
import org.zxl.api.vm.dto.CloudVmInfo;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");

        HttpClient httpClient = new HttpClient();
        CloudVmInfo cloudVmInfo = (CloudVmInfo) httpClient.get("", "http://localhost:8888/sss", new HttpHeaderBuilder() {
            @Override
            public String buildHttpHeader(String platformUuid) {
                //todo 从authInfo缓存中获取token等信息，组装http头信息
                AuthInfo authInfo = PlatformInfoCache.getAuthInfo(platformUuid);
                return "token=123456&aa=9";
            }
        }, new HttpResponseParse() {
            @Override
            public <T> T parse(String response, Class<T> c) {
                return JSON.parseObject(response, c);
            }
        }, new CheckAuthFailExceptionHandler() {
            @Override
            public boolean fail(Exception e, String response) {
                return false;
            }
        }, CloudVmInfo.class, "?a=11&b=22");

        System.out.println(JSON.toJSONString(cloudVmInfo));

    }
}